﻿/**
 *	(C) 2014 Yuanjj
 *
 * 	define db protocal
 *
 *	histroy
 * 		2014-08-08	Yuanjj		-	create
 */

#ifndef _DB_PROTOCAL_H_
#define _DB_PROTOCAL_H_

#include "typedef.h"
#include "protocal.h"

enum
{
    DB_USER_LOGIN	= 0x40,					// user login

    DB_HOST			= 0x44,					// load host
    DB_HOST_UPDATE,							// update host( add, del, modify )

    DB_TUNNEL_TYPE	= 0x48,					// load tunnel type
    DB_TUNNEL,								// load tunnel
    DB_TUNNEL_UPDATE,						// update tunnel
    DB_TUNNEL_DELETE,						// delete tunnel

    DB_DEV_TYPE		= 0x50,					// load device type
    DB_DEVICE,								// load device
    DB_DEVICE_UPDATE,						// update device
    DB_DEVICE_DELETE,						// delete device

    DB_PROTOCAL		= 0x58,					// load protocal

    DB_ALARM		= 0x60,					// load alarm

    DB_EVENT_TYPE	= 0x68,					// load event type
    DB_EVENT,								// load event

    DB_SCENE		= 0x70,					// load scene
    DB_SCENE_SAVE,							// save scene

    DB_FRAME		= 0x78,					// load frame

    // not exit 0x80
};

/**
 * 	description:	user login
 *	second:			DB_USER_LOGIN(0x40)
 * 	body:			db_user_login
 */
typedef struct _db_user_login
{
    pem_s8_t		account[USER_ACCOUNT_LEN];
    pem_s8_t		passwd[USER_PASSWORD_LEN];
} db_user_login;

/**
 * 	description:	load host
 *	second:			DB_HOST(0x44)
 * 	body:			db_host
 */
typedef struct _db_host
{
} db_host;

/**
 * 	description:	update host
 *	second:			DB_HOST_UPDATE(0x45)
 * 	body:			db_host_update
 */
typedef struct _db_host_update
{
    pem_s8_t		host[HOST_ID_LEN];
    pem_s8_t		name[HOST_NAME_LEN];
    pem_s8_t		ip[HOST_IP_LEN];
    pem_u16_t		port;
    pem_s32_t		status;				// 0:delete, 1:add, 2:modify, 3:connect, 4:disconnect
} db_host_update;

/**
 * 	description:	load tunnel type
 *	second:			DB_TUNNEL_TYPE(0x48)
 * 	body:			db_tunnel_type
 */
typedef struct _db_tunnel_type
{
} db_tunnel_type;

/**
 * 	description:	load tunnel
 *	second:			DB_TUNNEL(0x49)
 * 	body:			db_tunnel
 */
typedef struct _db_tunnel
{
} db_tunnel;

/**
 * 	description:	update tunnel
 *	second:			DB_TUNNEL_UPDATE(0x4A)
 * 	body:			db_tunnel_update
 */
typedef struct _db_tunnel_update
{
    pem_s8_t		host[HOST_ID_LEN];
    pem_s8_t		name[TUNNEL_NAME_LEN];
    pem_s8_t		type[TUNNEL_TYPE_LEN];
    pem_s8_t		number[TUNNEL_NUMBER_LEN];
    pem_s8_t		remark[REMARK_LEN];
    pem_s32_t		used;
} db_tunnel_update;

/**
 * 	description:	delete tunnel
 *	second:			DB_TUNNEL_DELETE(0x4B)
 * 	body:			db_tunnel_delete
 */
typedef struct _db_tunnel_delete
{
    pem_s8_t		host[HOST_ID_LEN];
    pem_s8_t		number[TUNNEL_NUMBER_LEN];
} db_tunnel_delete;

/**
 * 	description:	load device type form data base
 *	second:			DB_DEV_TYPE(0x50)
 * 	body:			db_dev_type
 */
typedef struct _db_dev_type
{
} db_dev_type;

/**
 * 	description:	load device form data base
 *	second:			DB_DEVICE(0x51)
 * 	body:			db_device
 */
typedef struct _db_device
{
} db_device;

/**
 * 	description:	update device into data base
 *	second:			DB_DEVICE_UPDATE(0x52)
 * 	body:			db_device_update
 */
typedef struct _db_device_update
{
    pem_s8_t		host[HOST_ID_LEN];
    pem_s8_t		dev_id[DEV_ID_LEN];
    pem_s8_t		dev_type[DEV_TYPE_LEN];
    pem_s8_t		dev_name[DEV_NAME_LEN];
    pem_s8_t		dev_pos[DEV_POS_LEN];
    pem_s8_t		machine[DEV_MACHINE_LEN];
    pem_s8_t		tunnel_num[TUNNEL_NAME_LEN];
    pem_s8_t		pto_name[PTO_NAME_LEN];
    pem_s8_t		pto_file[PTO_FILE_LEN];
    pem_s8_t		value[DEV_VALUE_LEN];
    pem_s32_t		x;
    pem_s32_t		y;
    pem_s32_t		setup;
} db_device_update;

/**
 * 	description:	load protocal form data base
 *	second:			DB_PROTOCAL(0x58)
 * 	body:			db_protocal
 */
typedef struct _db_protocal
{
} db_protocal;

/**
 * 	description:	load alarm form data base
 *	second:			DB_ALARM(0x60)
 * 	body:			db_alarm
 */
typedef struct _db_alarm
{
} db_alarm;

/**
 * 	description:	load event type form data base
 *	second:			DB_EVENT_TYPE(0x68)
 * 	body:			db_event_type
 */
typedef struct _db_event_type
{
} db_event_type;

/**
 * 	description:	load event form data base
 *	second:			DB_EVENT(0x69)
 * 	body:			db_event
 */
typedef struct _db_event
{
} db_event;

/**
 * 	description:	load scene form data base
 *	second:			DB_SCENE(0x70)
 * 	body:			db_scene
 */
typedef struct _db_scene
{
} db_scene;

/**
 * 	description:	save scene into data base
 *	second:			DB_SCENE_SAVE(0x71)
 * 	body:			db_scene_save
 */
typedef struct _db_scene_save
{
    pem_s8_t		img[SCENE_IMG_LEN];		// scene file
    pem_u32_t		receipt;				// receipt flag, 0: not receipt; 1:receipt
} db_scene_save;

/**
 * 	description:	load frame form data base
 *	second:			DB_FRAME(0x78)
 * 	body:			db_frame
 */
typedef struct _db_frame
{
} db_frame;

#endif // _DB_PROTOCAL_H_
